<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${namespace}">
    <resultMap id="baseResultMap" type="${type}">
        <id column="id" property="id" jdbcType="BIGINT" javaType="java.lang.Long"></id>
            <#list columnFieldList as cf>
                <#if "${cf.property}"!="id">
            <result column="${cf.column}" property="${cf.property}" jdbcType="${cf.jdbcType}"
                    javaType="${cf.javaType}"/>
                </#if>
            </#list>
    </resultMap>
    <sql id="allColumn">
            <#list columnList as column>
                ${column} <#if column_has_next>,</#if>
            </#list>
    </sql>
    <!-- 建表语句-->
    <update id="tableInit">
    ${tableInitSql}
    </update>

    <insert id="insert" parameterType="${type}">
        insert into ${tableName}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <#list columnFieldList as cf>
                <if test="${cf.property} != null">
                    ${cf.column},
                </if>
            </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
             <#list columnFieldList as cf>
                 <if test="${cf.property} != null">
                     ${"#"}{${cf.property}},
                 </if>
             </#list>
        </trim>
    </insert>
    <!-- 根据UID获取单条记录-->
    <select id="get" resultMap="baseResultMap" parameterType="java.lang.String">
        select
        <include refid="allColumn"/>
        from
    ${tableName}
        where uid=${"#"}{uid}
    </select>

    <select id="list" resultMap="baseResultMap" parameterType="${type}">
        select
        <include refid="allColumn"/>
        from
    ${tableName}
        <where>
            del_flag='0'
                 <#list columnFieldList as columnField>
                     <#if columnField.column!="id">
                        <if test="${columnField.property} != null and ${columnField.property} !=''">
                            and ${columnField.column}=${"#"}{${columnField.property}}
                        </if>
                     </#if>
                 </#list>
        </where>
    </select>


    <update id="update" parameterType="${type}">
        update ${tableName}
        <set>
                <#list columnFieldList as cf>
                <#if (cf.column!='id')>
            <if test="${cf.property} != null">
                ${cf.column}=${"#"}{${cf.property}},
            </if>
                </#if>
                </#list>
        </set>
        <where>
            uid=${"#"}{uid}
        </where>
    </update>
    <update id="batchDelete" parameterType="java.util.List">
        update ${tableName} set
        del_flag='1'
        WHERE uid
        <foreach close=")" collection="array" item="uid" open="in (" separator=",">
        ${"#"}{uid}
        </foreach>
    </update>
    <update id="delete" parameterType="java.lang.String">
        update ${tableName} set del_flag='1' where uid=${"#"}{uid}
    </update>


</mapper>